package com.bpz.utils;

import org.apache.log4j.Logger;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
 * User: ChuanQi Date: 13-5-16 Time: 下午11:15
 */
public class ConfigUtils {
	Properties prop = new Properties();
	Logger logger = Logger.getLogger(this.getClass());
	private static ConfigUtils instance = null;

	/*
	 * 单例
	 */
	public static ConfigUtils getInstance() {
		if (instance == null) {
			synchronized (ConfigUtils.class) {
				if (instance == null) {
					instance = new ConfigUtils();
				}
			}
		}
		return instance;
	}

	public ConfigUtils() {
		try {
			prop.load(getClass().getResourceAsStream("/config.properties"));
		} catch (FileNotFoundException e) {
			logger.error(e.getMessage());
		} catch (IOException e) {
			logger.error(e.getMessage());
		}
	}

	private String configFile;

	/* 配置文件地址 */
	public String getConfigFile() {
		return configFile;
	}

	public void setConfigFile(String configFile) {
		this.configFile = configFile;
	}

	/*
	 * 后台管理主机地址
	 */
	public String getServerName() {
		return prop.getProperty("admin.serverName");
	}

	public String getServerPath() {
		return prop.getProperty("admin.serverPath");
	}

	/**
	 * 后台超级用户
	 * 
	 * @return
	 */
	public String getSuperUser() {
		return prop.getProperty("admin.super.user");
	}

	/**
	 * 密码
	 * 
	 * @return
	 */
	public String getSuperPassword() {
		return prop.getProperty("admin.super.password");
	}

	/*
	 * 后台action后缀
	 */
	public String getAdmExtension() {
		return prop.getProperty("admin.ActionExt");
	}

    /**
     * 获取数据访问层的包名全路径
     * @return
     */
    public  String getDaoPackage(String daoName)
    {
        return  prop.getProperty("dao.package")+daoName;
    }
}
